// pages/chalu/chalu.js

const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mealsList: '', //员工工号
    networkUser: '', //总数据
    length: '', //数据长度
    BANK_ASSETS: '', //金额
    USER_ASSETS_NAME: '', //姓名
    USER_COUPON_PHONE: '', //电话
    USER_ASSETS_ID: '', //用户资产ID
    result: '', //判断是否插入成功
    allList: [], //获取的奖券
    COUPON_AMOUNT: '', //选择的数字

    showView: false,
    showView_a: false,

    wordKey: '', //搜索
    flag: true, //节流
    xinxi: true,



  },

  //获取单个奖券的数据
  but_shu: function (e) {
    console.log(e.target.dataset.item);
    this.setData({
      COUPON_AMOUNT: e.target.dataset.item
    })

    if (this.data.COUPON_AMOUNT == e.target.dataset.item) {
      this.setData({
        showView_a: (!this.data.showView_a)
      })
    }
  },





  //下拉框的显隐
  but_jq: function () {
    this.setData({
      showView_a: (!this.data.showView_a),

    })
  },


  //点击显示
  activation: function (e) {

    console.log(e);
    console.log(e.currentTarget.dataset.item);

    this.setData({
      // USER_ASSETS_NAME:e.currentTarget.dataset.item.USER_ASSETS_NAME,
      // USER_COUPON_PHONE:e.currentTarget.dataset.item.USER_COUPON_PHONE,
      // USER_ASSETS_ID:e.currentTarget.dataset.item.USER_ASSETS_ID,
    })



    this.setData({
      showView: (!this.data.showView),
    })

  },
  //刷新页面
  quno() {
    wx.redirectTo({
      url: '../../pages/youhuidafangsongjihuo/youhuidafangsongjihuo',
    })
  },



  tjok: function () {
    if (this.data.flag) {



      // if (this.data.COUPON_AMOUNT == '') {
      //   wx.showToast({
      //     title: '请选择优惠券',
      //     icon: 'none',
      //     duration: 3000
      //   })
      // } else {

        console.log(this.data.BANK_ASSETS);
        this.data.flag = false
        setTimeout(() => {
          console.log('-----------------', 1);
          this.data.flag = true
        }, 5000)
        wx.request({
          url: app.globalData.interface+'/shangluo/API_5307_shangluoGuoqingRaffleactivation',
          method: 'POST',
          data: {

            EMPLOYEE_ID: this.data.mealsList,
            OPEN_ID: this.data.openid, //用户OPEN_ID
            session_key: this.data.session_key,
            OPEN_UUID: this.data.jiami,
            USER_ASSETS_IDCARD: this.data.networkUser.USER_ASSETS_IDCARD,
            USER_PRIZE_ID: this.data.networkUser.USER_PRIZE_ID,
                      
          },

          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: function (res) {
            console.log(res.data.result);
            if (res.data.result != 'success') {
              wx.showModal({
                title: '温馨提示',
                content: res.data.data,
                success: function (res) {
                  if (res.confirm) { //这里是点击了确定以后
                    console.log('用户点击确定')
                  } else { //这里是点击了取消以后
                    console.log('用户点击取消')
                  }
                }
              })
            } else {
              wx.showModal({
                title: '温馨提示',
                content: res.data.data,
                success: function (res) {
                  if (res.confirm) { //这里是点击了确定以后
                    wx.redirectTo({
                      url: '../../pages/shangguoqinjihuo/shangguoqinjihuo',
                    })
                    console.log('用户点击确定')
                  } else { //这里是点击了取消以后
                    wx.redirectTo({
                      url: '../../pages/pages/shangguoqinjihuo/shangguoqinjihuo',
                    })
                    console.log('用户点击取消')
                  }
                }
              })
            }
          }
        })





      // }

    }
  },

  search_tow() {

    this.setData({
      wordKey: '',
      xinxi: true,
    })
  },


  search_but() {
    var that = this
    wx.request({
      url: app.globalData.interface+'/shangluo/API_5309_shangluoGuoqingRaffleSelect ',
      method: 'post',
      data: {
        EMPLOYEE_ID: that.data.mealsList,
        USER_ASSETS_IDCARD: that.data.wordKey,
        OPEN_ID: this.data.openid, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res);
        console.log(res.data.data);

        if (res.data.result != 'success') {
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后
                console.log('用户点击确定')
              } else { //这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })
        } else {

          that.setData({

            networkUser: res.data.data,
            xinxi: false,
          })
        }


      }
    })
  },





  //验证身份证

  idcardblur: function (e) {
    let idcard = e.detail.value;
    let reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;

    if (reg.test(idcard) == false) {
      this.setData({
        USER_IDCARD: ''
      })
      wx.showToast({
        title: '身份证号码有误',
        icon: 'none',
        duration: 3000
      })
    } else {
      this.setData({
        card_id: idcard
      })

    }

  },


  handleInput() {

    wx.request({
      url: app.globalData.interface+'/squareDance/API_5331_selectpostBigBroadcastPrize',
      method: 'POST',
      data: {

        EMPLOYEE_ID: this.data.mealsList,
        OPEN_ID: this.data.openid, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        // console.log(res.data.allList);

        this.setData({

          allList: res.data.data
        })
      }
    })
  },






  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    console.log(e);
    this.setData({
      mealsList: app.globalData.mealsList,

      openid: app.globalData.openid,

      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
    });
    console.log(this.data.mealsList);


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {


    this.handleInput()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})